<?php
class MY_Controller extends CI_Controller{
	protected $tpl;
	protected $pmsuserinfo;
	public function __construct(){
		parent::__construct();
		$this->initsmarty();
		$this->load->library('session');
		$this->load->library('Js');
		//*****PMSROOT 为当前访问服务器 、
		$this->assign('pmsroot',PMSROOT);
		$getconfig=sys_config('base');
		$this->assign('getconfig',$getconfig);
	}
	//是否登陆
	protected function isLogin(){
		if(isset($_SESSION['pmsuserinfo'])){
			$this->pmsuserinfo=unserialize($_SESSION['pmsuserinfo']);
			$this->assign('pmsuserinfo',$this->pmsuserinfo);
			return true;
		}else{
			if(isset($_POST) && !empty($_POST)){
				ajax_return(0,'登陆过期');
			}else{
				header('location:/Login/login');
			}
			exit;
		}
	}
	//超级管理员
	protected function isItAdministrator(){
		if($this->pmsuserinfo['isitadministrator']==1){
			return true;
		}else{
			if(isset($_POST) && !empty($_POST)){
				ajax_return(0,'没有权限');
			}else{
				echo Js::alert("没有权限");
			}
			exit;
		}
	}
	protected function initsmarty(){
		require_once(BASEPATH.'/libraries/smarty/Smarty.class.php');  
		$this->tpl=new Smarty();
		$this->tpl->template_dir=VIEWPATH;   //默认模版设置
		$this->tpl->compile_dir=FCPATH."cache/compile_cache";    //编译缓存文件夹路径
		$this->tpl->cache_dir=FCPATH."cache/cache";  //缓存文件夹路径
		$this->tpl->left_delimiter   ='<{';    //配置变量左侧识别符
		$this->tpl->right_delimiter  ='}>';     //配置变量右侧识别符
		$this->tpl->caching        = 0;    //是否开启缓存
		$this->tpl->cache_lifetime =0;  //缓存时间
		$this->tpl->compile_check=1;
		$this->tpl->php_handling = 1;
	}
	protected function assign($key,$val){
			$this->tpl->assign($key,$val);
	}
	protected function display($html,$cache_id=false,$compile_id=false){
			$html=ltrim($html,'/');
			$this->tpl->display($html,$cache_id,$compile_id);
	}
	protected function fetch($html,$cache_id=false,$compile_id=false){
			return $this->tpl->fetch($html,$cache_id,$compile_id);
	}
}
?>
